package com.ruoyi.web.controller.hotel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hotel.domain.HotelHouse;
import com.ruoyi.hotel.domain.vo.ChangeHouseStatus;
import com.ruoyi.hotel.domain.vo.DeleteHotelCheckRecord;
import com.ruoyi.hotel.domain.vo.HotelCheckRecord;
import com.ruoyi.hotel.service.IHotelHouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hotel.domain.HotelCheckHouseRecord;
import com.ruoyi.hotel.service.IHotelCheckHouseRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入住记录Controller
 *
 * @author sunye
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/hotel/houseRecord")
@Api(tags = "入住记录")
public class HotelCheckHouseRecordController extends BaseController
{
    @Autowired
    private IHotelCheckHouseRecordService hotelCheckHouseRecordService;

    @Autowired
    private IHotelHouseService hotelHouseService;

    /**
     * 查询入住记录列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:houseRecord:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询入住记录列表")
    public TableDataInfo list(HotelCheckHouseRecord hotelCheckHouseRecord)
    {
        startPage();
        List<HotelCheckHouseRecord> list = hotelCheckHouseRecordService.selectHotelCheckHouseRecordList(hotelCheckHouseRecord);
        return getDataTable(list);
    }

    /**
     * 导出入住记录列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:houseRecord:export')")
    @Log(title = "入住记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelCheckHouseRecord hotelCheckHouseRecord)
    {
        List<HotelCheckHouseRecord> list = hotelCheckHouseRecordService.selectHotelCheckHouseRecordList(hotelCheckHouseRecord);
        ExcelUtil<HotelCheckHouseRecord> util = new ExcelUtil<HotelCheckHouseRecord>(HotelCheckHouseRecord.class);
        util.exportExcel(response, list, "入住记录数据");
    }

    /**
     * 查询所有房间列表
     */
    @GetMapping("/allList")
    @ApiOperation(value = "查询所有房间列表")
    public AjaxResult allList(HotelHouse hotelHouse)
    {
        List<HotelHouse> list = hotelHouseService.selectHotelHouseList(hotelHouse);
        return success(list);
    }


    /**
     * 切换房间状态
     */
    @Log(title = "切换房间状态", businessType = BusinessType.INSERT)
    @PostMapping("/changeHouseStatus")
    @ApiOperation(value = "切换房间状态")
    public AjaxResult changeHouseStatus(@RequestBody ChangeHouseStatus changeHouseStatus)
    {
        return toAjax(hotelHouseService.changeHouseStatus(changeHouseStatus));
    }

    /**
     * 入住登记
     */
    @Log(title = "入住登记", businessType = BusinessType.INSERT)
    @PostMapping("checkInRegister")
    @ApiOperation(value = "入住登记")
    public AjaxResult checkInRegister(@RequestBody HotelCheckRecord hotelCheckRecord)
    {
        hotelCheckRecord.setCreateId(getUserId());
        return toAjax(hotelCheckHouseRecordService.checkInRegister(hotelCheckRecord));
    }


    /**
     * 添加入住人员
     */
    @Log(title = "添加入住人员", businessType = BusinessType.INSERT)
    @PostMapping("addCheckInPeople")
    @ApiOperation(value = "添加入住人员")
    public AjaxResult addCheckInPeople(@RequestBody HotelCheckRecord hotelCheckRecord)
    {
        hotelCheckRecord.setCreateId(getUserId());
        return toAjax(hotelCheckHouseRecordService.addCheckInPeople(hotelCheckRecord));
    }


    /**
     * 删除入住人员
     */
    @Log(title = "删除入住人员", businessType = BusinessType.INSERT)
    @PostMapping("deleteCheckInPeople")
    @ApiOperation(value = "删除入住人员")
    public AjaxResult deleteCheckInPeople(@RequestBody DeleteHotelCheckRecord deleteHotelCheckRecord)
    {
        deleteHotelCheckRecord.setCreateId(getUserId());
        return toAjax(hotelCheckHouseRecordService.deleteCheckInPeople(deleteHotelCheckRecord));
    }


    /**
     * 入住详情
     */
    @GetMapping("checkInDetail/{houseId}")
    @ApiOperation(value = "入住详情")
    public AjaxResult checkInDetail(@PathVariable("houseId") Long houseId)
    {
        return success(hotelCheckHouseRecordService.checkInDetail(houseId));
    }

    /**
     * 确认退房
     */
    @GetMapping("confirmCheckOut/{houseId}")
    @Log(title = "确认退房", businessType = BusinessType.INSERT)
    @ApiOperation(value = "确认退房")
    public AjaxResult confirmCheckOut(@PathVariable("houseId") Long houseId)
    {
        Long userId = getUserId();
        return success(hotelCheckHouseRecordService.confirmCheckOut(houseId,userId));
    }


    /**
     * 查看所有房间状态数量
     */
    @GetMapping("getHouseStatusNumber")
    @ApiOperation(value = "查看所有房间状态数量")
    public AjaxResult getHouseStatusNumber()
    {
        return success(hotelHouseService.getHouseStatusNumber());
    }

}
